package com.xiaogao.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiaogao.common.entity.PageData;
import com.xiaogao.common.entity.Result;
import com.xiaogao.sys.model.SysRole;
import com.xiaogao.sys.request.role.AddParam;
import com.xiaogao.sys.request.role.QueryParam;
import com.xiaogao.sys.request.role.UpdateParam;
import com.xiaogao.sys.response.SysRoleResponse;
import com.xiaogao.sys.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.String;
import java.util.List;

@RestController
@RequestMapping("/sys/role")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping("/query/select")
    public Result<List<SysRole>> querySelect(){
        List<SysRole> list = sysRoleService.list(new LambdaQueryWrapper<>());
        return Result.success(list);
    }

    @PostMapping("/list")
    public Result<PageData<SysRoleResponse>> list(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                  @RequestParam(required = false, defaultValue = "30") Integer pageSize,
                                                  @RequestBody QueryParam queryParam){
        PageData<SysRoleResponse> pageData = sysRoleService.querySelective(pageNum,pageSize,queryParam);
        return Result.success(pageData);
    }

    @PostMapping("/add")
    public Result<Object> add(@RequestBody AddParam addParam){
        sysRoleService.add(addParam);
        return Result.success();
    }

    @PutMapping("/update")
    public Result<Object> update(@RequestBody UpdateParam updateParam){
        sysRoleService.update(updateParam);
        return Result.success();
    }

    @PostMapping("/delete")
    public Result<Object> delete(@RequestBody List<String> ids){
        sysRoleService.delete(ids);
        return Result.success();
    }

    @GetMapping("/queryPermIds/{roleId}")
    public Result<List<String>> queryPermIds(@PathVariable("roleId")String roleId){
        List<String> permIds = sysRoleService.queryPermIds(roleId);
        return Result.success(permIds);
    }
}
